<?php
require_once 'connector_interface.php';

class connector implements connector_interface
{
	private var $handle;
	private var $server;
	private var $user;
	private var $password;
	private var $database;
	

	
	public function connect($server, $user, $password)
	{
		$this->server = $server;
		$this->user = $user;
		$this->password = $password;
		$this->handle = mysql_connect($server, $user, $password);
		
		return $this->is_connected();		
	}
	
	public function is_connected()
	{
		return $this->handle ? true : false;
	}
	
	public function disconnect()
	{
		@mysql_close($this->handle);
	}
	
	public function list_databases()
	{
		if(!is_connected()) return NULL;
		
		$database_names = array();
		$databases = mysql_list_dbs($this-handle);

		while ($database = mysql_fetch_object($databases))
		{
		     $database_names[] =  $database->Database;
		}
		
		return $database_names;
	}
	
	public function add_database($name);
	public function remove_database($name);
	public function change_database_name($name);
	public function use_database($name);

	public function list_tables();
	public function add_table($name);
	public function remove_table($name);
	public function change_table_name($name, $newname);
	
	public function list_rows($table);
	public function add_row(); // returns the id for the added row
	public function remove_row($id);
	
	public function list_fields($table);
	public function add_field($table, $name, $type);
	public function remove_field($table, $name);
	public function change_field_type($table, $field, $type);

	public function update_value($id, $field, $value);